import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import i18n from './i18n'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale'
import enLocale from 'element-ui/lib/locale/lang/en'
import zhLocale from 'element-ui/lib/locale/lang/zh-CN'
import VueCodemirror from 'vue-codemirror'
import 'codemirror/lib/codemirror.css'
import 'codemirror/theme/material.css'
import 'codemirror/mode/sql/sql.js'
import 'codemirror/addon/hint/show-hint.css'
import 'codemirror/addon/hint/show-hint.js'
import 'codemirror/addon/hint/sql-hint.js'

Vue.config.productionTip = false

// Set initial Element UI locale based on saved language
const savedLanguage = localStorage.getItem('influxdb_settings')
const lang = savedLanguage ? JSON.parse(savedLanguage).language : 'en'
locale.use(lang === 'zh' ? zhLocale : enLocale)

Vue.use(ElementUI)
Vue.use(VueCodemirror)

new Vue({
  router,
  store,
  i18n,
  render: h => h(App)
}).$mount('#app')